// THIS PAGE CONTANINS ALL THE JAVASCRIPT FUNCTIONS USED FOR ALL LARGE AND MEDIUM VIEWS

function createXMLHttpRequest() {
   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
   try { return new XMLHttpRequest(); } catch(e) {}
   alert("XMLHttpRequest not supported");
   return null;
 }
var xhReq = createXMLHttpRequest();
// This function is for switching the watch button for all medium and large views
function changewatch(id,lid,type){
	var img='watch'+id;
	var src1=document[img].src;
	var simg=src1.split("/B7/");
	//alert("kkk"+simg[1]+"kkk");
	if(simg[1]=="watch.gif"){
		//alert("put");
	    xhReq.open("GET", "/watchput_inc.php?log_id="+lid+"&user_id="+id+"&type=add&etype="+type, true);
		document[img].src=simg[0]+"/B7/stopwatch.gif";
	 }else{
		//alert("stop");
		xhReq.open("GET", "/watchstop_inc.php?log_id="+lid+"&user_id="+id+"&type=del&etype="+type, true);
		document[img].src=simg[0]+"/B7/watch.gif";
	}
	xhReq.onreadystatechange = onSumchangewatch;
	xhReq.send(null);
}function onSumchangewatch(){
	if (xhReq.readyState != 4)  { return; }
	var serverResponse = xhReq.responseText;
	//alert(serverResponse);
}function managewatch(id,lid,type){
	    if(type=='user'){
		  xhReq.open("GET", "/manage_alerts.php?log_id="+lid+"&user_id="+id+"&type=delalert&etype=user", true);
		}else if(type=='question'){
		  xhReq.open("GET", "/manage_questions.php?log_id="+lid+"&user_id="+id+"&type=delalert&etype="+type,true);
		}else{
          xhReq.open("GET", "/manage_story.php?log_id="+lid+"&user_id="+id+"&type=delalert&etype="+type,true);
		}
        xhReq.onreadystatechange = alertResponse;
	    xhReq.send(null);
}function alertResponse(){
	if (xhReq.readyState != 4)  { return; }
	var serverResponse = xhReq.responseText;
	//alert(serverResponse);
	var cell= document.getElementById('alert');
	cell.innerHTML = serverResponse;
}function addComment(id)
{
	var frm = document.getElementById("responsefrm");
	var cell=document.getElementById("res"+id);
	cell.innerHTML='<div id="report-form"><h5 class="response">Report This</h5><label for="subject">Please enter your concerns </label><fieldset><textarea id="responsemes" name="responsemes" rows="20" cols="30"></textarea><br/><input value="Submit" type="button" onclick="javascript:responsemail();" class="form-submit"> &nbsp;<INPUT onclick="javascript:CancelResponse('+id+');" type="button" value="Cancel" class="form-submit"></fieldset></div>';
	frm.resKW.value="ADD";
	frm.resid.value=id;
}function responsemail(){
	var frm = document.getElementById("responsefrm");
	var mval=document.getElementById("responsemes").value;
    frm.mailmesg.value=mval;
	if(GenValidation(frm.mailmesg,'Message',"","")==0)
		return false;
	frm.submit();
}

function CancelResponse(id)
{
	var cell=document.getElementById("res"+id);
	cell.innerHTML='';
}

function addVote(id,qid,uid,type,dtype){
	if(type=="story")
     	xhReq.open("GET", "/addvotestory.php?id="+id+"&qid="+qid+"&uid="+uid+"&dtype="+dtype, true);
	else
        xhReq.open("GET", "/addvote.php?id="+id+"&qid="+qid+"&uid="+uid+"&dtype="+dtype, true);
	if(dtype=="home"){
       document.getElementById("new").value=qid;
	   xhReq.onreadystatechange = onSumResponsehome;
	   xhReq.send(null);
	}else{
		xhReq.onreadystatechange = onSumResponse;
		xhReq.send(null);
	}
}function onSumResponse(){
	if (xhReq.readyState != 4)  { return; }
	var serverResponse = xhReq.responseText;
	Cell = document.getElementById("addvote"); 
    Cell.innerHTML=serverResponse;
}function onSumResponsehome(){
	if (xhReq.readyState != 4)  { return; }
	var serverResponse = xhReq.responseText;
	var val = document.getElementById("new").value;
	var Cell= document.getElementById(val);
    Cell.innerHTML=serverResponse;
}function addVoteresponse(id,qid,uid,type){
	document.getElementById("new").value=qid;
	if(type=="story")
   	   xhReq.open("GET", "/addvote.php?id="+id+"&rid="+qid+"&uid="+uid+"&type=response2", true);
	else
       xhReq.open("GET", "/addvote.php?id="+id+"&rid="+qid+"&uid="+uid+"&type=response", true);
	xhReq.onreadystatechange = onSumaddVoteresponse;
	xhReq.send(null);
}
function getRelatedContent(nid, type){
	//alert("In RR " + nid + type);
	if(type!=''){
		xhReq.open("GET", "/node/"+nid+"/rc/"+type, true);
		xhReq.onreadystatechange = onGetRelatedNews;
    }
	else {
		xhReq.open("GET", "/node/"+nid+"/rc/blog", true);
		xhReq.onreadystatechange = onGetRelatedNews;
	}
    xhReq.send(null);
}

function onGetRelatedNews(){
    if (xhReq.readyState != 4)  { return; }
    var serverResponse = xhReq.responseText;
//    alert("Got RR " + serverResponse);
	var Cell=document.getElementById("news-encoder");
    Cell.innerHTML=serverResponse;
}

function addMemberVoting(vote,nid,uid,type){

	if(uid<1){
		alert("Please Sign in to OStatic to vote.");
		return;
	}
	
	document.getElementById("new").value=nid;
	// Pattern: /node/157943/addvote/1027/review/1
    xhReq.open("GET", "/node/"+nid+"/addvote/"+uid+"/"+type+"/"+vote, true);
    xhReq.onreadystatechange = onSumaddVoteresponse;
    xhReq.send(null);
}

function onSumaddVoteresponse(){
	if (xhReq.readyState != 4)  { return; }
	var serverResponse = xhReq.responseText;
	var val = document.getElementById("new").value;
	var Cell= document.getElementById(val);
    Cell.innerHTML=serverResponse;
}function gosearch(id){
	var frm=document.gosearch;
	frm.searchtext.value=id;
	var searchtext=frm.searchtext.value;
	frm.action="/search/"+searchtext;
	frm.submit();
}function getMouseXY(e) {
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	alert('event page x = ' + posx + 'event pos y = ' + posy);

 }function closeerrormess(){
    document.getElementById("errframe").style.display='none';
	document.getElementById("footerframe").style.display='none';
}function closeerrorfeedback(){
	document.getElementById("feedbackframe").style.display='none';
}function closeerrorproject(){
	document.getElementById("projectframe").style.display='none';
}function getMouseOXY(e) {
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
}
function getMousePXY(e) {
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posA = e.pageX;
		posB = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posA = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posB = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
}
function getMouseXY(e) {
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posa = e.pageX;
		posb = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posa = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posb = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
}
function ossprojgotoerror(){
    //alert(document.getElementById("errframe").style.visibility);
	document.getElementById('example1').onclick = getMouseOXY;
	document.getElementById("ossprojerrframe").style.display ='';
    //show("errframe");
    document.getElementById("ossprojerrframe").innerHTML='<div id="pContainer" style="position: absolute; left: posxpx; top: posypx; width: 300px; z-index: 1000;"><table border="0" cellpadding="0" cellspacing="0" width="300"><tbody><tr><td><table class="errorDiv" id="colorIt" border="0" cellpadding="0" cellspacing="0"><tbody><tr height="2"><td width="5%"></td><td width="83%"></td><td width="5%"></td><td width="1%"></td></tr><tr><td></td><td></td><td><div align="right"><img src="/themes/B7/close.gif" onclick="closeosserrormess()" border="0" height="15" width="17"></div></td><td></td></tr><tr><td></td><td><div id="textContainer">You need to be signed in, in order to use this feature.</div></td><td></td><td></td></tr><tr height="15"></tr></tbody></table></td></tr></tbody></table></div>';
    //document.getElementById("errframe").style.display='';
}
function pssprojgotoerror(){
    //alert(document.getElementById("errframe").style.visibility);
	document.getElementById('example2').onclick = getMousePXY;
	document.getElementById("pssprojerrframe").style.display ='';
    //show("errframe");
    document.getElementById("pssprojerrframe").innerHTML='<div id="pContainer" style="position: absolute; left: posApx; top: posBpx; width: 200px; z-index: 1000;"><table border="0" cellpadding="0" cellspacing="0" width="300"><tbody><tr><td><table class="errorDiv" id="colorIt" border="0" cellpadding="0" cellspacing="0"><tbody><tr height="2"><td width="5%"></td><td width="83%"></td><td width="5%"></td><td width="1%"></td></tr><tr><td></td><td></td><td><div align="right"><img src="/themes/B7/close.gif" onclick="closepsserrormess()" border="0" height="15" width="17"></div></td><td></td></tr><tr><td></td><td><div id="textContainer">You need to be signed in, in order to use this feature.</div></td><td></td><td></td></tr><tr height="15"></tr></tbody></table></td></tr></tbody></table></div>';
    //document.getElementById("errframe").style.display='';
}

function addreviewerror(){
    //alert(document.getElementById("errframe").style.visibility);
	document.getElementById('display-review').onclick = getMouseXY;
	document.getElementById("dev-display-review").style.display ='';
    //show("errframe");
    document.getElementById("dev-display-review").innerHTML='<div id="pContainer" style="position: absolute; left: posapx; top: posbpx; width: 300px; z-index: 1000;"><table border="0" cellpadding="0" cellspacing="0" width="300"><tbody><tr><td><table class="errorDiv" id="colorIt" border="0" cellpadding="0" cellspacing="0"><tbody><tr height="2"><td width="5%"></td><td width="83%"></td><td width="5%"></td><td width="1%"></td></tr><tr><td></td><td></td><td><div align="right"><img src="/themes/B7/close.gif" onclick="closereviewmess()" border="0" height="15" width="17"></div></td><td></td></tr><tr><td></td><td><div id="textContainer">You need to be signed in, in order to use this feature.</div></td><td></td><td></td></tr><tr height="15"></tr></tbody></table></td></tr></tbody></table></div>';
    //document.getElementById("errframe").style.display='';
}
function closereviewmess(){
document.getElementById("dev-display-review").style.display ='none';
}
function closeosserrormess(){
	document.getElementById("ossprojerrframe").style.display='none';
}
function closepsserrormess(){
	document.getElementById("pssprojerrframe").style.display='none';
}function gotoerror(){
    //alert(document.getElementById("errframe").style.visibility);
	document.getElementById("errframe").style.display ='';
    //show("errframe");
    document.getElementById("errframe").innerHTML='<div id="pContainer" style="position: absolute; left: 133.5px; top: 108px; width: 300px; z-index: 1000;"><table border="0" cellpadding="0" cellspacing="0" width="300"><tbody><tr><td><table class="errorDiv" id="colorIt" border="0" cellpadding="0" cellspacing="0"><tbody><tr height="2"><td width="5%"></td><td width="83%"></td><td width="5%"></td><td width="1%"></td></tr><tr><td></td><td></td><td><div align="right"><img src="/themes/B7/close.gif" onclick="closeerrormess()" border="0" height="15" width="17"></div></td><td></td></tr><tr><td></td><td><div id="textContainer">You need to be signed in, in order to use this feature.</div></td><td></td><td></td></tr><tr height="15"></tr></tbody></table></td></tr></tbody></table></div>';
    //document.getElementById("errframe").style.display='';
}
function gotofooter(){
    //alert(document.getElementById("errframe").style.visibility);
	document.getElementById("footerframe").style.display ='';
    //show("errframe");
    document.getElementById("footerframe").innerHTML='<div id="pContainer" style="position: absolute; left: 133.5px; top: 1488px; width: 300px; z-index: 1000;"><table border="0" cellpadding="0" cellspacing="0" width="300"><tbody><tr><td><table class="errorDiv" id="colorIt" border="0" cellpadding="0" cellspacing="0"><tbody><tr height="2"><td width="5%"></td><td width="83%"></td><td width="5%"></td><td width="1%"></td></tr><tr><td></td><td></td><td><div align="right"><img src="/themes/B7/close.gif" onclick="closeerrormess()" border="0" height="15" width="17"></div></td><td></td></tr><tr><td></td><td><div id="textContainer">You need to be signed in, in order to use this feature.</div></td><td></td><td></td></tr><tr height="15"></tr></tbody></table></td></tr></tbody></table></div>';
    //document.getElementById("errframe").style.display='';
}
function feedbackfooter(){
    //alert(document.getElementById("errframe").style.visibility);
	document.getElementById("feedbackframe").style.display ='';
    //show("errframe");
    document.getElementById("feedbackframe").innerHTML='<div id="pContainer" style="position: absolute; left: 133.5px; top: 462px; width: 300px; z-index: 1000;"><table border="0" cellpadding="0" cellspacing="0" width="300"><tbody><tr><td><table class="errorDiv" id="colorIt" border="0" cellpadding="0" cellspacing="0"><tbody><tr height="2"><td width="5%"></td><td width="83%"></td><td width="5%"></td><td width="1%"></td></tr><tr><td></td><td></td><td><div align="right"><img src="/themes/B7/close.gif" onclick="closeerrorfeedback()" border="0" height="15" width="17"></div></td><td></td></tr><tr><td></td><td><div id="textContainer">You need to be signed in, in order to use this feature.</div></td><td></td><td></td></tr><tr height="15"></tr></tbody></table></td></tr></tbody></table></div>';
    //document.getElementById("errframe").style.display='';
}
function projectfooter(){
    //alert(document.getElementById("errframe").style.visibility);
	document.getElementById("projectframe").style.display ='';
    //show("errframe");
    document.getElementById("projectframe").innerHTML='<div id="pContainer" style="position: absolute; left: 133.5px; top: 658px; width: 300px; z-index: 1000;"><table border="0" cellpadding="0" cellspacing="0" width="300"><tbody><tr><td><table class="errorDiv" id="colorIt" border="0" cellpadding="0" cellspacing="0"><tbody><tr height="2"><td width="5%"></td><td width="83%"></td><td width="5%"></td><td width="1%"></td></tr><tr><td></td><td></td><td><div align="right"><img src="/themes/B7/close.gif" onclick="closeerrorproject()" border="0" height="15" width="17"></div></td><td></td></tr><tr><td></td><td><div id="textContainer">You need to be signed in, in order to use this feature.</div></td><td></td><td></td></tr><tr height="15"></tr></tbody></table></td></tr></tbody></table></div>';
    //document.getElementById("errframe").style.display='';
}function ge()
{
  var ea;
  for( var i = 0; i < arguments.length; i++ ) {
    var e = arguments[i];
    if( typeof e == 'string' )
      e = document.getElementById(e);
    if( arguments.length == 1 )
      return e;
    if( !ea )
      ea = new Array();
    ea[ea.length] = e;
  }
  return ea;
}

function show()
{
  for( var i = 0; i < arguments.length; i++ ) {
    var element = ge(arguments[i]);
    if (element && element.style) element.style.display = '';
  }
  return false;
}

function odeskExpertSearch(){
    var newurl="http://www.odesk.com/users";
    var frm=document.getElementById("odeskexpertsearchform");
    var text=frm.odesksearchtext.value;
    text =escape(text);
    alert(text + " Hi2 " + frm.odesksearchtext.value );
    if(text != ''){
    	newurl = 'http://www.odesk.com/users/?search_button.x=1&filter%5BProfileData%5D='+text;
    }
    location.href=newurl;
}

function odeskJobSearch(){
    var newurl="http://www.odesk.com/jobs/";
    var frm=document.getElementById("odeskjobsearchform");
    var text=frm.odeskjobsearchtext.value;
    text =escape(text);
    if(text != ''){
		newurl = "http://www.odesk.com/jobs?search_button.x=1&filter%5BOpeningData%5D="+text;
    }
    location.href=newurl;
}
//For 'I Use This' software on project page
function addIUseThisSoftware(userid,projid){
    if(userid!="" && userid > 0){
        xhReq.open("GET","/project/usethis/add/"+projid+"/"+userid,true);
		xhReq.onreadystatechange = onSumclickuseAdd;
        xhReq.send(null);
    }else {
        alert("Please Sign in to OStatic to add this project to your profile.");
    }
}
//For 'I Use This' functionality for all softwares
function addIUseThisSoftwares(userid,projid){
    if(userid!="" && userid > 0){
        xhReq.open("GET","/project/usethis/add/"+projid+"/"+userid,true);
		xhReq.onreadystatechange = onSumclickuseAdds;
        xhReq.send(null);
		if(document.getElementById("app-users"+projid).style.display=='none'){
			// Increment the value by one user
			//var count = document.getElementById("iusethiscount").value;
			//count++;
			//document.getElementById("iusethiscount2").innerHTML= count + "<span class=\"count-text\">
			//use this</span>";
			document.getElementById("app-users"+projid).style.display='';
			document.getElementById("app-use"+projid).style.display='none';
		}else{
			document.getElementById("app-use"+projid).style.display='';
			document.getElementById("app-users"+projid).style.display='none';
		}

    }else {
        alert("Please Sign in to OStatic to add this project to your profile.");
    }
}

//For 'I Use This' functionality for all softwares at "Happening new on OStatic" widget.
function addIUseThis(userid,projid){
    if(userid!="" && userid > 0){
        xhReq.open("GET","/project/usethis/add/"+projid+"/"+userid,true);
		xhReq.onreadystatechange = onSumclickuseAdds;
        xhReq.send(null);
		if(document.getElementById("app-users_"+projid).style.display=='none'){
			// Increment the value by one user
			//var count = document.getElementById("iusethiscount").value;
			//count++;
			//document.getElementById("iusethiscount2").innerHTML= count + "<span class=\"count-text\">
			//use this</span>";
			document.getElementById("app-users_"+projid).style.display='';
			document.getElementById("app-use_"+projid).style.display='none';
		}else{
			document.getElementById("app-use_"+projid).style.display='';
			document.getElementById("app-users_"+projid).style.display='none';
		}

    }else {
        alert("Please Sign in to OStatic to add this project to your profile.");
    }
}

function removeIUseThisSoftware(userid,projid){
    if(userid!="" && userid > 0){
        xhReq.open("GET","/project/usethis/delete/"+projid+"/"+userid,true);
		xhReq.onreadystatechange = onSumclickuseRemove;
        xhReq.send(null);
        document.getElementById("usethis_"+projid).style.display='none';
    }else {
        alert("Please Sign in to OStatic to remove this project to your profile.");
    }
}
function onSumclickuseRemove(){
    if (xhReq.readyState != 4)  { return; }
    var serverResponse = xhReq.responseText;
}

function onSumclickuseAdd(){
    if (xhReq.readyState != 4)  { return; }
    var serverResponse = xhReq.responseText;
    if(document.getElementById("app-users").style.display=='none'){
        // Increment the value by one user
        //var count = document.getElementById("iusethiscount").value;
        //count++;
        //document.getElementById("iusethiscount2").innerHTML= count + "<span class=\"count-text\">
        //use this</span>";
        document.getElementById("app-users").style.display='';
        document.getElementById("app-use").style.display='none';
    }else{
        document.getElementById("app-use").style.display='';
        document.getElementById("app-users").style.display='none';
    }
    //cell.innerHTML = serverResponse;
}


function onSumclickuseAdds(){
    if (xhReq.readyState != 4)  { return; }
    var serverResponse = xhReq.responseText;
    //cell.innerHTML = serverResponse;
}
//Function for adding a related question

function QuestionAdd(uid){

 var frm=document.getElementById("addrelquestion");
 if(uid!="" && uid > 0){
	 if((frm.question.value=="")||(frm.question.value=="Have a question? Ask the community")){
			alert("Please enter a question");
			frm.question.focus();
			return false;
	 }
	 frm.submit();
 }else {
        alert("Please Sign in to OStatic to submit your question.");
		return false;
 }
}

function isUserSignedIn(){
	var uid = document.getElementById("user-links");
	uid = document.getElementById("profileid").value;
	return uid;
}
/* Used by ostatic.js */
function ostaticgv( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( '?'+ostaticv );
  if( results == null )
    return "";
  else
    return results[1];
}
function removeAlternative(mnid,anid){
	var frm=document.getElementById("removealtfrm");
	frm.mnid.value=mnid;
	frm.anid.value=anid;
	if(confirm("Do you really want to remove this Alternative?")){
	frm.KW.value="DELALT";
	frm.submit();
	}
}

function removeImage(mnid,inid){
	var frm=document.getElementById("removeimgfrm");
	frm.mnid.value=mnid;
	frm.inid.value=inid;
	if(confirm("Do you really want to remove this Screenshot?")){
	frm.KW.value="DELIMAGE";
	frm.submit();
	}
}
/* function for deleting question comment by admin */
function delquescomment(id){
	var frm=document.getElementById("delquescomment");
	frm.comid.value=id;
	if(confirm("Do you really want to remove this Comment?")){
	frm.KWD.value="DELCOM";
	frm.submit();
	}
}

/* function for deleting project comment by admin */
function delprojcomment(id){
	var frm=document.getElementById("delprojcomment");
	frm.comid.value=id;
	if(confirm("Do you really want to remove this Comment?")){
	frm.KWD.value="DELCOM";
	frm.submit();
	}
}

/* function for deleting blog comment by admin */
function delblogcomment(id){
	var frm=document.getElementById("delblogcomment");
	frm.comid.value=id;
	if(confirm("Do you really want to remove this Comment?")){
	frm.KWD.value="DELCOM";
	frm.submit();
	}
}