var ip_voted = 0;
var username='',password='';
var security_twice = 0;
		
if (document.cookie.length > 0) { // if there are any cookies
			var search =  "username&";
			var search1 = "username=";
			offset = document.cookie.indexOf(search);
			if (offset == -1) offset = document.cookie.indexOf(search1);
			if (offset != -1) { // if cookie exists 
				offset += search.length ;  // set index of beginning of value
				end = document.cookie.indexOf("&", offset); // set index of end of cookie value
				if (end == -1) end = document.cookie.indexOf(";", offset); // set index of end of cookie value
				if (end == -1) end = document.cookie.length;
				username = unescape(document.cookie.substring(offset, end));
			}
			var search =  "password&";
			var search1 = "password=";
			offset = document.cookie.indexOf(search);
			if (offset == -1) offset = document.cookie.indexOf(search1);
			if (offset != -1) { // if cookie exists 
				offset += search.length ;  // set index of beginning of value
				end = document.cookie.indexOf("&", offset); // set index of end of cookie value
				if (end == -1) end = document.cookie.indexOf(";", offset); // set index of end of cookie value
				if (end == -1) end = document.cookie.length;
				password = unescape(document.cookie.substring(offset, end));
			}
}
try {  // Firefox, Opera 8.0+, Safari  
	xmlHttpP=new XMLHttpRequest(); 
}
catch (e) {  // Internet Explorer  
	try {
		xmlHttpP=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e) {   
		 try {
		 	   xmlHttpP=new ActiveXObject("Microsoft.XMLHTTP");
		 }
	  	 catch (e)  {
	 		   alert("Your browser does not support AJAX!");  
			}
	}
}
xmlHttpP.onreadystatechange=function() {
			if(xmlHttpP.readyState==4) {	 
						var html = xmlHttpP.responseText; 					
						putAjaxStyle(html);
 						document.getElementById('poll1').innerHTML = html;
 			}
}
	  
xmlHttpP.open("GET","/cgi-webaxy/vote/vote.pl?username=uriya&password=966069&ID=902167_ghaimm&lang=he&num=1&act=voteform&noheader=1&style=1",true);
xmlHttpP.send(null);
	  
function putAjaxStyle(rawHTML) {
  	
		var headEl = null;  // lazy-load
		styles = rawHTML.split(/\n/);
		var style = 0, stop = 1;
		var newStyleEl = document.createElement('style');
		newStyleEl.type = 'text/css';
		var styleIE = '';
		// add all found style blocks to the HEAD element.
    if (!headEl) {  
    		headEl = document.getElementsByTagName('head')[0];
        if (!headEl) return;
    }
    for (i = 0; i < styles.length; i++) {
        if (styles[i].search(/<style>/i) >= 0){
        		style = 1;
        		stop = 0;
        		continue;
        }
        else if (styles[i].search(/<\/style>/i) >= 0){
        		style = 0
        }
        else if (styles[i].search(/^\s*\/\*/) >= 0) {
        		stop = 1;
        		continue;
        }
        else if (styles[i].search(/\*\/\s*$/) >= 0) {
        		stop = 0;
        		continue;
        }
        if (style == 0 || stop == 1) continue;
        if (navigator.appVersion.indexOf("MSIE")!=-1) {  
            styleIE += styles[i]
        }
        else {  
            var cssDefinitionsEl = document.createTextNode(styles[i]);
            newStyleEl.appendChild(cssDefinitionsEl);
        }
     }
     if (navigator.appVersion.indexOf("MSIE")!=-1 && styleIE != '') newStyleEl.styleSheet.cssText = styleIE;
     headEl.appendChild(newStyleEl);
    
}		
	
function checkPoll() {
		
		if (!navigator.cookieEnabled) {
			alert("לא ניתן להצביע, עליך לאפשר\n Cookies");
			return false;
		}		
		 
		if (document.form1.age && (document.form1.age.selectedIndex == 0)) {
			alert("נא לבחור ");
			document.form1.age.focus();
			return false;
		}
		
		var no_ans = true;
		for (i=0;i<document.form1.ans.length;i++) 
			if (document.form1.ans[i].checked)
				no_ans = false;
		if (no_ans) {
			alert("נא לבחור תשובה");
			document.form1.ans[0].focus();
			return false;
		}
		if (!check_cookie(0)) {
			return false;
		}
		//submit the form and update vote div
		if ('cur_window_with_template' == 'cur_window_with_template') {
		//if ('cur_window_with_template'.search(/cur_window_with_template/) >= 0) {
				document.form1.submit();
		 }
		else if ('cur_window_with_template' == 'new_window') {
				document.form1.setAttribute('target', '_new');
		 		document.form1.submit();
		}
		else if ('cur_window_with_template' == 'cur_window') {
				var xmlHttp;
				try {  // Firefox, Opera 8.0+, Safari  
					xmlHttp=new XMLHttpRequest(); 
				}
				catch (e) {  // Internet Explorer  
					try {
						xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
					}
					catch (e) {   
						 try {
						 	   xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
						 }
				   	 catch (e)  {
				  		   alert("Your browser does not support AJAX!");  
				   		   return false;
						}
					}
				}
			  xmlHttp.onreadystatechange=function() {
			  			if(xmlHttp.readyState==4) {	  					
			  					if ("no" == "yes") {
										alert("תודה על השתתפותך בסקר");
									}	
									else {
										var htmlRaw = xmlHttp.responseText;
			  						document.getElementById('vote1-main_div').innerHTML = htmlRaw;
			  					}
			  			}
			  	}
			  
			  var addUrl = '';
			  for(i=0;i<document.form1.ans.length;i++) {
					if (document.form1.ans[i].checked == true)	
			   		addUrl += 'ans='+document.form1.ans[i].value;
			  }
			  if (document.form1.age) addUrl += '&age='+document.form1.age.value;
			  if (document.form1.IP) addUrl += '&IP='+document.form1.IP.value;
			  //alert("/cgi-webaxy/vote/vote.pl?noheader=1&username=uriya&password=966069&ID=902167_ghaimm&lang=he&act=vote&num=1&"+addUrl);
			  xmlHttp.open("GET","/cgi-webaxy/vote/vote.pl?style=1&noheader=1&username=uriya&password=966069&ID=902167_ghaimm&lang=he&act=vote&num=1&"+addUrl,true);
			  xmlHttp.send(null);
		}
				
	}
	
	function check_cookie(op) {
		
		var gc = get_cookie("webaxy_902167_ghaimm vote 1");
		var errmsg0 = "לא ניתן להצביע פעמיים בסקר";
		var errmsg = "תוכל להצביע שוב רק אחרי 0 שעות";
		
		if ('' == '1' && (username == '' || password == '')) {
				//self.location.replace('/cgi-webaxy/checkLogin.pl?ID=902167_ghaimm&accessType=1&act=go2app&app=vote&appAct=act=voteform<D>num=1');
				self.location.replace('/cgi-webaxy/checkLogin.pl?ID=902167_ghaimm&accessType=1&act=go2URL&url='+self.location);
				//loadMe('poll1_login','/cgi-webaxy/checkLogin.pl?ID=902167_ghaimm&accessType=1&outerTemplate=&act=go2URL&url='+self.location);
				//document.getElementById('vote1-main_div').style.display = 'none';
				return false;
		}
		
		if (((ip_voted == 1 || gc) && '0' == '0') || security_twice == 1) {
				if (op == 0) alert(errmsg0);
				return false;
		}
		
		if (!gc)
			gc = 0;
		var today = new Date();
		var expi = (gc < today.getTime());
		// on load 
		if ((op == 1) && (!expi)) { 					// voter is back
				alert(errmsg);
				return false;			
		}
		else if (op == 1) {
			return true;
		}		
		
		// on submit - set the cookie
		if (expi) {
			exDate = new Date();
			if (0 == 0) {
				set_cookie("webaxy_902167_ghaimm vote 1",exDate.getTime()+"",null);
			}
			else {
				exDate.setTime(today.getTime() + 1000*0);
				set_cookie("webaxy_902167_ghaimm vote 1",exDate.getTime()+"",exDate);
			}
			return true;
		}
		else {
			alert(errmsg);
			return false;
		}
		
	}
	
	function loadMe(id, url) {
		
			var xmlHttp;
			try {  // Firefox, Opera 8.0+, Safari  
					xmlHttp=new XMLHttpRequest(); 
			}
			catch (e) {  // Internet Explorer  
							try {
								xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
							}
							catch (e) {   
								 try {
								 	   xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
								 }
						   	 catch (e)  {
						  		   alert("Your browser does not support AJAX!");  
						   		   return false;
								}
							}
			}
			xmlHttp.onreadystatechange=function() {
					if(xmlHttp.readyState==4) {
							rawHTML = xmlHttp.responseText;
							rawHTML = rawHTML.replace(/<html>.*<body>/i,'');							
							//putAjaxStyle(rawHTML);
							document.getElementById(id).innerHTML = rawHTML;
					}
			}
					  
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
		
	}

