function set_select(sel_name,form_name,sel_index){

sel_length=eval("document."+form_name+"."+sel_name+".length");

for (optionCounter = 0; optionCounter < sel_length; optionCounter++){

         if (eval("document."+form_name+"."+sel_name+".options[optionCounter].value=='"+sel_index+"'")){

            eval("document."+form_name+"."+sel_name+".selectedIndex=optionCounter");

         }

}

}

function upload_win(pkd,max,rst){

        window.open(path_index+'?upload&pp=up&PKD='+pkd+'&max='+max+'&rst='+rst,'upload','width=400,height=400,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no,left=0,top=0,screenx=50,screeny=50');

}

function set_checked(check_name,form_name,checked_mode){
        if(checked_mode==1){
                eval("document."+form_name+"."+check_name+".checked=true");
        }
}

function url_escape(string){

        out = "/";
        add = "&#47;";
        temp = "" + string;

        while (temp.indexOf(out)>-1) {
                pos= temp.indexOf(out);
                temp = "" + (temp.substring(0, pos) + add +
                temp.substring((pos + out.length), temp.length));
        }
        temp=escape(temp);
        return temp;

}

function check_input(user,pass,pass_retype,email){
   if(user==''){
      alert("Username missing!");
      return false;
   }
   else if(pass==''){
      alert("Password missing!");
      return false;
   }
   else if(pass_retype!=pass){
      alert("Passwords does not match!");
      return false;
   }
   else if(email==''){
      alert("Email address missing!");
      return false;
   }
   else{
      return true;
   }
}

var http_request = false;
var result = "";
   
function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
         }
      } 
	  else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = http_get_res;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
	  
	  if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            // alert(http_request.responseText);
            result = http_request.responseText;
            // document.getElementById('myspan').innerHTML = result;            
         } else {
            // alert('There was a problem with the request.');
         }
      }
	  
}
   
   
function http_get_res() {
   
	var chat_request_uid = "";
	var chat_request_channel = "";
	var chat_request_username = "";
	var my_username = "";
	
	  if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            eval(result);
		if (chat_request_uid > 0) {
	            	if (confirm(chat_request_username + " has started a chat conversation with you.\n\nWould you like to accept the chat request?")) {
				// alert("open chat window on channel" + chat_request_channel);				
				if (requested_from == "toolbar") {
					window.open("/loadchat.php?mode=join&usrname=" + my_username + "&channel_key=" + chat_request_channel, "Chat" + chat_request_uid, "width=750,height=500,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=no'");
				}
				else {
					document.location.href = "/loadchat.php?mode=join&usrname=" + my_username + "&channel_key=" + chat_request_channel;
				}
			}
			else {
				//makePOSTRequest("/check_chat.php?mode=reject&channel=" + chat_request_channel, "");
	            		//alert("The chat request was rejected");
			}
		}
         } else {
            // alert('There was a problem with the request.');
         }
      }
	  
}

function check_chat(){
	makePOSTRequest("/check_chat.php?mode=request", "");
}

// Set a simple cookie
function set_cookie(name, value){
	
	var argv = set_cookie.arguments;
	var argc = set_cookie.arguments.length;
	var expires;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	
	expires = new Date ();
	expires.setTime(expires.getTime() + (1 * 24 * 3600 * 1000));
	
	document.cookie = name + "=" + escape(value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) +((secure == true) ? "; secure" : "");
	
}

function redirect_site(site_key, site_lang) {
	
	var sex = document.getElementById("sex").value;
	if (site_key == 1 && sex == 5) {
		window.location = "http://www.singlemenonline.com/signup.php"
	}
	else if (site_key == 2  && sex == 4) {
		window.location = "http://www.foreignwomen.com/signup.php"
	}
	else if (site_key == 3 && site_lang == "en" && sex == 4) {
		window.location = "http://women.asiansingles.com/signup.php"
	}
	else if (site_key == 3 && site_lang == "en" && sex == 5) {
		window.location = "http://men.asiansingles.com/signup.php"
	}	
	else if (site_key == 3 && site_lang == "cn" && sex == 4) {
		window.location = "http://cn.women.asiansingles.com/signup.php"
	}
	else if (site_key == 3 && site_lang == "cn" && sex == 5) {
		window.location = "http://cn.men.asiansingles.com/signup.php"
	}
	else if (site_key == 4 && sex == 5) {
		window.location = "http://www.singlemenonline.com/signup.php"
	}
	else if (site_key == 5 && sex == 4) {
		set_cookie('SSEX', 5);
		window.location = "http://philippine-singles.com/signup.php"
	}
	else if (site_key == 5 && sex == 5) {
		set_cookie('SSEX', 4);
		window.location = "http://philippine-singles.com/signup.php"
	}
	else if (site_key == 6 && sex == 4) {
		set_cookie('SSEX', 5);
		window.location = "http://foreignjewishbrides.com/signup.php"
	}
	else if (site_key == 6 && sex == 5) {
		set_cookie('SSEX', 4);
		window.location = "http://foreignjewishbrides.com/signup.php"
	}			
}
