
var xmlhttp =  false;
var ds =  "", c, s, cd;

function
sendpdfrequest()  {
	window.open('contactus.html','Contact Us','scrollbars=yes');
	}


function
setcs()  {
	i =  document.cookie.indexOf("cgram=");
	if ( i >= 0 )  {
		cd =  document.cookie.substring( i + 6 );
		c =  cd.split("#")[0];
		s =  cd.split("#")[1];
		}
	else  {
		c =  "";
		s =  "";
		}
	}

function
contactfocus()  {
	setcs();
	//alert("Cookie " + document.cookie +" stripped " +c );
	list =  c.split("+");
	if ( list[0] == "")  {
		document.getElementById("nopdf").style.display = "";
		for ( i = 0;  i < 20;  i++ )  {
			elt =  document.getElementById("row" + i );
			if ( ! elt )  {
				break;
				}
			elt.style.display = "none";
			}
		if ( ! s )  {
			document.getElementById("reset").style.display = "none";
			}
		else  {
			document.getElementById("reset").style.display = "";
			}
		return;
		}
	document.getElementById("nopdf").style.display = "none";
	document.getElementById("reset").style.display = "";
	for ( i = 0;  i < 20;  i++ )  {
		elt =  document.getElementById("row" + i );
		if ( ! elt )  {
			break;
			}
		elt.style.display = "";
		str =  list[ i * 2 ];
		if ( ! str )  {
			break;
			}
		elt =  document.getElementById("row" + i );
		if ( elt )  {
			elt.style.display = "";
			}
		elt =  document.getElementById("item" + (i * 2) );
		elt.style.display = "";
		appendstr( elt, str );
		elt =  document.getElementById("item" + ((i * 2) + 1) );
		inp =  document.getElementById("input" + ((i * 2) + 1) );
		str =  list[ (i * 2) + 1 ];
		if ( str )  {
			elt.style.display = "";
			inp.style.display = "";
			appendstr( elt, str );
			}
		else  {
			elt.style.display = "none";
			inp.style.display = "none";
			i++;
			break;
			}
		}
	for (;  i < 20;  i++ )  {
		elt =  document.getElementById("row" + i );
		if ( ! elt )  {
			break;
			}
		elt.style.display = "none";
		}
	}


function
appendstr( elt, str )  {
	eltchild =  elt.firstChild;
	if ( eltchild )  {
		elt.removeChild( eltchild );
		}
	elt.appendChild( document.createTextNode( str ) );
	}

function
addpdfrequest( pdf )  {
	var	namestr;
	setcs();
	namestr = pdf + "+";
	//alert("pdf " +pdf +", namestr " +namestr +", c " +c
								//+", posn " +c.indexOf( namestr ) );
	if ( c.indexOf( namestr ) < 0 )  {
		cd =  c + namestr;
		document.cookie =  "cgram=" +cd +"#" +cd;
		//alert("cd " +cd +", cookie " +document.cookie );
		}
	}

function
pdfdelete( no )  {
	//alert("pdfdelete" + no );
	setcs();
	list =  c.split("+");
	str =  "";
	for ( i = 0;  list[i] != "";  i++ )  {
		if ( i != no )  {
			str =  str + list[i] + "+";
			}
		}
	document.cookie =  "cgram=" +str + "#" + s;
	contactfocus();
	}

function
pdfreset()  {
	var	c;
	setcs();
	document.cookie =  "cgram=" + s + "#" + s;
	contactfocus();
	}

var xmlhttp = null;
function
sendrequest( str )  {
	if ( xmlhttp == null )  {
		/*@cc_on
		/*@if ( @_jscript_version >= 5 )  {
			try {
				xmlhttp =  new ActiveXObject("Msxml2.XMLHTTP");
				}
			catch ( e )  {
				try {
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
					}
				catch ( E )  {
					xmlhttp = false;
					}
				}
			}
		@else  {
			xmlhttp = false;
			}
		@end @*/
		if ( ! xmlhttp  &&  typeof XMLHttpRequest != 'undefined')  {
			try  {
				xmlhttp = new XMLHttpRequest();
				}
			catch (e)  {
				xmlhttp = false;
				}
			}
		}
	if ( ! xmlhttp  ||  document.getElementById("thankyou") == null )  {
		alert("Your browser does not support AJAX\nYou have to use a more modern browser or call us");
		return;
		}
	emailstr =  document.getElementById("email").value;
	ext= "";
	i =  emailstr.indexOf('@');
	if ( i > 0 )  {
		ext =  emailstr.substring( i + 1 );
		if ( (i = ext.indexOf('.')) > 0 )  {
			ext =  ext.substring( i + 1 );
			}
		else  {
			ext =  "";
			}
		}
	if ( ext.length < 2 )  {
		document.getElementById("errormesg").style.display = "";
		return;
		}
	emailt =  codestr( document.getElementById("email").value );
	fnamet =  codestr( document.getElementById("fname").value );
	snamet =  codestr( document.getElementById("sname").value );
	subjt =  codestr( document.getElementById("subj").value );
	demot =  codestr( document.getElementById("demo").value );
	textt =  codestr( document.getElementById("text").value );
	coyt =  codestr( document.getElementById("coy").value );
	telt =  codestr( document.getElementById("tel").value );
	skypet =  codestr( document.getElementById("skype").value );
	pdflist = document.cookie.split("#")[0].substring( 6 );
	text = "email:" +emailt +"?fname:" +fnamet +"?sname:" +snamet
		+"?subj:" +subjt +"?demo:" +demot +"?text:" +textt
		+"?coy:" +coyt +"?tel:" +telt +"?skype:" +skypet
		+"?pdfs:" +pdflist;
	xmlhttp.open("GET", "/cgi-bin/cgram.cgi?data="+encodeURI(text), true );
	xmlhttp.onreadystatechange = function()  {
		if ( xmlhttp.readyState == 4 )  {
     			ds =  xmlhttp.responseText
			// alert("Reply is " + ds );
			i = ds.indexOf("<html>");
			eval( ds.substring( i + 6 ) );
			}
		}
	xmlhttp.setRequestHeader("Content-Type", "text/xml");
	xmlhttp.send(null);
	} 

function
codestr( txt )
	{
	txt =  txt.replace(/\~/g,'~1').replace(/:/g,'~2')
		.replace(/;/g,'~3').replace(/\?/g,'~4').replace(/\&/g,'~5');
	return txt;
	}


function
loadclientarea()  {
	window.location="protected/clientarea.html";
	}

function
showvideo( url, name )
	{
	//alert("url " +url +", name " +name );
	window.open('demo/' +url, name, 'resizable=yes');
	}

